package com.example.demo.Service;

import com.example.demo.Constant.Constants;
import com.example.demo.Mapper.LoginMapper;
import com.example.demo.Pojo.User;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//登录
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    LoginMapper loginMapper;


    @Override
    public User login(User user) {

        //user1是从数据库中获取到的User对象
        User user1 = loginMapper.login(user.getName());


        if (user1 == null) {
            throw new RuntimeException(Constants.ACCOUNT_NOT_FOUND);
        }
        if(user1.getPassword().equals(user.getPassword())){

            throw new RuntimeException(Constants.PASSWORD_ERROR);
        }

        return user1;

    }
}
